<template>
  <div>
    <div class="search-top">
      <router-link to="/home">
        <van-icon name="arrow-left" color="#333" size="0.2rem" class="box" />
      </router-link>
      <form action="/">
        <van-search
          v-model="value"
          show-action
          placeholder="请输入搜索关键词"
          @input="Todo"
          shape="round"
        >
          <template #action>
            <div @click="onSearch">搜索</div>
          </template>
        </van-search>
      </form>
      <div class="search-wrapper" v-if="value">
        <div class="wrapper-b">
          <ul>
            <li v-for="(e, i) in msg" :key="i">
              <div class="col-mar col-12" v-html="e"></div>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="box-cate">
      <div class="hr"></div>
      <div class="search-hot">
        <p class="hot-title">三步轻松获得优惠券</p>
        <div class="hot-box">
          <div class="hot1">
            <img
              src="https://cmsstatic.ffquan.cn//wap_new/search/images/step1.png?v=202106101527"
              alt=""
            />
            <p>1.进入淘宝</p>
          </div>
          <div class="hot1">
            <img
              src="https://cmsstatic.ffquan.cn//wap_new/search/images/step2.png?v=202106101527"
              alt=""
            />
            <p>2.复制商品标题</p>
          </div>
          <div class="hot1">
            <img
              src="https://cmsstatic.ffquan.cn//wap_new/search/images/step3.png?v=202106101527"
              alt=""
            />
            <p>3.点击搜索查询</p>
          </div>
        </div>
      </div>
    </div>
    <div class="hr"></div>
  </div>
</template>
<script lang="ts">
import { computed, defineComponent, reactive, toRefs } from "vue";
import { useStore } from "vuex";
import _ from "lodash";
export default defineComponent({
  setup() {
    const state = reactive({
      value: "",
    });

    const store = useStore();
    const msg = computed(() => store.state.search.msg);

    const Todo = () => {
      _.debounce(() => {
        store.dispatch({
          type: "search/getSearch",
          kw: state.value,
        });
      }, 1000)();
    };
    return {
      Todo,
      ...toRefs(state),
      msg,
    };
  },
});
</script>
<style lang="stylus" scoped>
* {
  margin: 0;
  padding: 0;
}

ul, li {
  list-style: none;
}

.search-top {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 5;
}

.box-cate {
  padding-top: 0.5rem;
}

.box {
  display: block;
  position: absolute;
  top: 0.15rem;
  left: 0.05rem;
}

.hr {
  background: #F5F5F5;
  height: 0.1rem;
}

.col-mar {
  margin: 0 0.1rem;
}

.search-wrapper {
  color: #333;
  white-space: normal;
  word-break: break-all;
  font-size: 0.14rem;
  position: absolute;
  z-index: -1;
  zoom: 1;
  top: 0;
  width: 100%;
  transition: all 0.4s ease 0s;
  height: 100vh;
  transform: translateY(0) translateX(0);
  opacity: 1;
  background: #fff;

  .wrapper-b {
    padding-top: 0.46rem;
    padding-bottom: 0.7rem;

    ul {
      display: block;
      line-height: 0.4rem;

      li {
        border-bottom: 1px solid #eee;

        .col-12 {
          width: 83.33%;
        }
      }
    }
  }
}

.search-hot {
  padding: 0.13rem 0 0.15rem;

  .hot-title {
    margin-bottom: 0.11rem;
    height: 0.18rem;
    font-size: 0.13rem;
    font-weight: 600;
    color: #333;
    line-height: 0.18rem;
    margin-left: 0.17rem;
  }

  .hot-box {
    position: relative;
    z-index: 1;
    zoom: 1;
    text-align: center;
    display: flex;
    justify-content: center;

    .hot1 {
      display: flex;
      align-items: center;
      justify-content: center;

      img {
        height: 0.2rem;
        width: 0.2rem;
      }

      p {
        font-size: 0.1rem;
        margin: 0 0.1rem;
        color: #555;
      }
    }
  }
}

.van-search {
  padding: 0.1rem 0rem 0.1rem 0.36rem;
}
</style>
